/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package envasesdeleste.persistencia.broker;

import envasesdeleste.dom.Categoria;
import envasesdeleste.dom.IPersistente;
import envasesdeleste.persistencia.Broker;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 *
 * @author MAT
 */
public class BrokerCategoriasAccess extends Broker{
    
    public BrokerCategoriasAccess(Categoria objA) {
        super(objA);
  }

    @Override
    public String getInsertCommand() {
        Categoria cat =(Categoria)this.getObjP();
        return "INSERT INTO CATEGORIAS(Codigo, Nombre)" + "VALUES(" + cat.getCod() + ",'" + cat.getNom() +"')";
        
    }

    @Override
    public String getUpdateCommand() {
         Categoria cat =(Categoria)this.getObjP();
         return "UPDATE CATEGORIAS SET Nombre='" + cat.getNom() + "' WHERE Codigo=" +cat.getCod();
            
    }

    @Override
    public String getDeleteCommand() {
         Categoria cat =(Categoria)this.getObjP();
         return "DELETE FROM Categorias " + " WHERE Codigo='" +cat.getCod()+"'";
    }

    @Override
    public String getSelectCommand() {
        return "SELECT * FROM Categorias";
    }

    @Override
    public void obtenerDesdeResultSet(ResultSet rs, Object IPersistentej) {
        try {
                Categoria cat=(Categoria)IPersistentej;
		cat.setCod(rs.getInt("Numero"));
                cat.setNom(rs.getString("Nombre"));
                } catch (SQLException e) {
			System.out.println("ERROR AL OBTENER LAS CATEGORIAS");
		}
    }

    @Override
    public IPersistente getNuevo() {
        return new Categoria();
    }

    @Override
    public String getSelectCommand(int numfactura) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    
}
